//Sunday, December 06 2009
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class OlympicCandles
{
public:
	int numberOfNights(vector <int> candles)
	{
		int ret = 0;
		int N = candles.size();
		while(true)
		{
			ret ++;
			sort(candles.begin(), candles.end());
			for(int i=0; i<ret; i++)
			{
				if(N-1-i < 0 || candles[N-1-i] == 0)
					return ret-1;
				else candles[N-1-i]--;;
			}
		}
		return ret;
	}
};
